﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace NetCore和EF使用CodeFirst生成数据库.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            using (MyDbContext ctx = new MyDbContext())
            {
                //Person p = new Person();
                //p.Id = 101;
                //p.Name = "张三";
                //p.AddTime = DateTime.Now;
                //p.Gender = false;

                //ctx.Persons.Add(p);

                //ctx.SaveChanges();


                User u = new User();
                u.Id = 1;
                u.Name = "张三";
                ctx.Users.Add(u);


                Role r = new Role();
                r.Id = 1;
                r.Name = "管理员";
                ctx.Roles.Add(r);


                UserRole ur = new UserRole();
                ur.Id = 1;
                ur.RoleId = r.Id;
                //ur.Role = r;

                ur.UserId = u.Id;
                ctx.UserRoles.Add(ur);

                ctx.SaveChanges();
                


            }



                return View();
        }
    }
}